package com.cdshop.mvc;

import java.util.List;

import javax.servlet.jsp.PageContext;

import com.cdshop.comm.BusinessException;
import com.cdshop.dao.CartDAO;
import com.cdshop.dao.obj.CartGoods;
import com.cdshop.entity.User;
import com.cdshop.web.PageUtil;

public class CartPM extends AbstractPM {

	private static final long serialVersionUID = 1L;

	private List<CartGoods> goods;

	public List<CartGoods> getGoods() {
		return goods;
	}

	public void setGoods(List<CartGoods> goods) {
		this.goods = goods;
	}

	@SuppressWarnings("unchecked")
	@Override
	public void populate(PageContext pctx) throws BusinessException {
		goods = (List<CartGoods>) pctx.getRequest().getAttribute("CartPM.goods");
		if (goods == null) {
			User user=PageUtil.loginUser(pctx);
			goods = CartDAO.instance().list(user.getId());
			pctx.getRequest().setAttribute("CartPM.goods", goods);
		}
	}
}
